<?php
/**
 * 邮件日志控制器
 */

namespace app\admin\controller;

use app\common\model\Department;
use app\common\model\Staff;
use think\Request;
use app\common\model\EmailLog;

use app\common\validate\EmailLogValidate;

class EmailLogController extends Controller
{

    //列表
    public function index(Request $request, EmailLog $model)
    {
        $param = $request->param();
        if (isset($param['salary_time'])) {
            $param['salary_time'] = strtotime($param['salary_time']);
        }
        $model  = $model->scope('where', $param)->order('id desc');

        $data = $model->paginate($this->admin['per_page'], false, ['query'=>$request->get()]);
        //关键词，排序等赋值
        $this->assign($request->get());

        $this->assign([
            'data'  => $data,
            'staff_list'=>Staff::all(),
            'page'  => $data->render(),
            'total' => $data->total(),
        ]);
        return $this->fetch();
    }
    //删除
    public function del($id, EmailLog $model)
    {
        if (count($model->noDeletionId) > 0) {
            if (is_array($id)) {
                if (array_intersect($model->noDeletionId, $id)) {
                    return error('ID为' . implode(',', $model->noDeletionId) . '的数据无法删除');
                }
            } else if (in_array($id, $model->noDeletionId)) {
                return error('ID为' . $id . '的数据无法删除');
            }
        }

        if ($model->softDelete) {
            $result = $model->whereIn('id', $id)->useSoftDelete('delete_time', time())->delete();
        } else {
            $result = $model->whereIn('id', $id)->delete();
        }

        return $result ? success('操作成功', URL_RELOAD) : error();
    }

    
}
